// 资金流向
import { defineComponent, reactive, computed } from "vue";
import { dxget } from "../../util/index";
import store from "../../store";
export default defineComponent({
  props: {
    code: {
      type: String,
    },
  },
  setup(props) {
    let state = reactive({
      datas: {
        f136: 0,
        f135: 0,
        f137: 0,
      },
    });
    const initData = async () => {
      let { data }: any = await dxget("dc/getZJLXData", {
        code: props.code,
      });
      state.datas = data;
    };
    initData();
    const currentTime = computed(() => {
      const newDate = new Date();
      const Hours = newDate.getHours();
      const myddy = newDate.getDay(); //获取存储当前日期
      /*每天的15点以后 和9点前 周六和周天 不刷新 */
      console.log(myddy);
      if (Hours > 15 || Hours < 8 || myddy == 6 || myddy == 0) {
        return;
      }
      initData();
      return store.state.currentTime;
    });
    const UnitProcessing = (num) => {
      let isminus = false;
      if (num < 0) {
        num = -num;
        isminus = true;
      }
      let jiner = num;
      if (jiner / 100000000 >= 1) {
        jiner = parseFloat("" + jiner / 100000000).toFixed(2) + "亿";
      } else if (jiner / 110000 >= 1) {
        jiner = parseFloat("" + jiner / 10000).toFixed(2) + "万";
      }
      return (isminus ? "-" : "") + jiner;
    };
    return () => (
      <>
        <div>
          <n-card title="资金流向(万)" data-currentTime={currentTime.value}>
            <n-grid cols="3" class="cen">
              <n-gi class="red">
                <p class="fz14">主力流入</p>
                <p class="fz22">
                  <span>{UnitProcessing(state.datas.f135)}</span>
                </p>
              </n-gi>
              <n-gi class="ls">
                <p class="fz14">主力流出</p>
                <p class="fz22">{UnitProcessing(state.datas.f136)}</p>
              </n-gi>
              <n-gi class={state.datas.f137 > 0 ? "red" : "ls"}>
                <p class="fz14">主力净流入</p>
                <p class="fz22">{UnitProcessing(state.datas.f137)}</p>
              </n-gi>
            </n-grid>
          </n-card>
        </div>
      </>
    );
  },
});
